package com.example.technologyintroandroid;

import sheep.game.Sprite;
import sheep.graphics.Image;
import sheep.util.Timer;

public class Helicopter3 extends Sprite{
	
	private int width, height, speedX = (int) (40*Math.random()+40), speedY = (int) (40*Math.random()+40);
	private Image image, image2, image3, image4;
	private Timer timer;
	private float checkTime;

	public Helicopter3(Image image, Image image2, Image image3, Image image4, int width, int height){
		super(image);
		this.timer = new Timer();
		this.image = image;
		this.image2 = image2;
		this.image3 = image3;
		this.image4 = image4;
		this.width = width;
		this.height = height;
		this.checkTime = 0;
		this.setPosition((float) (width*Math.random()), (float) (height*Math.random()));
		this.setSpeed(-speedX, speedY);
	}
	
	@Override
	public void update(float dt) {
		super.update(dt);
		System.out.println("Printing checkTime:   "+checkTime);
		if(checkTime<0.1){
			checkTime += timer.getDelta();
			System.out.println(checkTime);
		}else{
			checkTime = 0;
			if(this.getView().equals(image)) this.setView(image2);
			else if(this.getView().equals(image2)) this.setView(image3);
			else if(this.getView().equals(image3)) this.setView(image4);
			else if(this.getView().equals(image4)) this.setView(image);
		}
		
		if(this.getPosition().getX()<=100){
			this.setSpeed(speedX, this.getSpeed().getY());
			this.setScale(-1, 1);
			this.setPosition(200, this.getPosition().getY());
		}
		if (this.getPosition().getX()>=width-70){
			this.setSpeed(-speedX, this.getSpeed().getY());
			this.setScale(1, 1);
			this.setPosition(width-75, this.getPosition().getY());
		}
		if(this.getPosition().getY()<=30){
			this.setSpeed(this.getSpeed().getX(), speedY);
		}
		if(this.getPosition().getY()>=height-70){
			this.setSpeed(this.getSpeed().getX(), -speedY);
		}
	}
}
